package com.ruoyi.myweb.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.myweb.domain.FoodShop;
import com.ruoyi.myweb.service.IFoodShopService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 店铺管理Controller
 * 
 * @author ruoyi
 * @date 2023-09-19
 */
@RestController
@RequestMapping("/food/shop")
public class FoodShopController extends BaseController
{
    @Autowired
    private IFoodShopService foodShopService;

    /**
     * 查询店铺管理列表
     */
    @PreAuthorize("@ss.hasPermi('food:shop:list')")
    @GetMapping("/list")
    public TableDataInfo list(FoodShop foodShop)
    {
        startPage();
        List<FoodShop> list = foodShopService.selectFoodShopList(foodShop);
        return getDataTable(list);
    }

    /**
     * 导出店铺管理列表
     */
    @PreAuthorize("@ss.hasPermi('food:shop:export')")
    @Log(title = "店铺管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FoodShop foodShop)
    {
        List<FoodShop> list = foodShopService.selectFoodShopList(foodShop);
        ExcelUtil<FoodShop> util = new ExcelUtil<FoodShop>(FoodShop.class);
        util.exportExcel(response, list, "店铺管理数据");
    }

    /**
     * 获取店铺管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('food:shop:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(foodShopService.selectFoodShopById(id));
    }

    /**
     * 新增店铺管理
     */
    @PreAuthorize("@ss.hasPermi('food:shop:add')")
    @Log(title = "店铺管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FoodShop foodShop)
    {
        return toAjax(foodShopService.insertFoodShop(foodShop));
    }

    /**
     * 修改店铺管理
     */
    @PreAuthorize("@ss.hasPermi('food:shop:edit')")
    @Log(title = "店铺管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FoodShop foodShop)
    {
        return toAjax(foodShopService.updateFoodShop(foodShop));
    }

    /**
     * 删除店铺管理
     */
    @PreAuthorize("@ss.hasPermi('food:shop:remove')")
    @Log(title = "店铺管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(foodShopService.deleteFoodShopByIds(ids));
    }
}
